Page({
  data: {
    orderInfo: {
      orderNumber: 'TD202311080001',
      pickupCode: 'A102',
      estimatedTime: '2023-11-08 18:30',
      status: 'ready', // preparing, ready, completed
      statusText: '待取餐',
      pickupAddress: 'TDesign咖啡店 - 取餐柜台',
      products: [
        {
          id: 1,
          name: '拿铁咖啡',
          spec: '大杯/热/标准糖',
          price: '32.00',
          quantity: 1,
          image: '/images/coffee1.jpg'
        },
        {
          id: 2,
          name: '巧克力蛋糕',
          spec: '切片',
          price: '28.00',
          quantity: 1,
          image: '/images/cake1.jpg'
        },
        {
          id: 3,
          name: '美式咖啡',
          spec: '中杯/冰',
          price: '25.00',
          quantity: 1,
          image: '/images/coffee2.jpg'
        }
      ],
      amount: {
        productTotal: '85.00',
        packingFee: '2.00',
        discount: '5.00',
        total: '82.00'
      }
    }
  },
  
  onLoad: function(options) {
    // 从URL参数获取订单ID
    if (options.orderId) {
      this.loadOrderData(options.orderId);
    }
  },
  
  loadOrderData: function(orderId) {
    // 模拟API调用获取订单数据
    // 实际开发中这里应该是wx.request
    console.log('加载订单数据:', orderId);
  },
  
  cancelOrder: function() {
    wx.showModal({
      title: '取消订单',
      content: '确定要取消这个订单吗？',
      success: (res) => {
        if (res.confirm) {
          wx.showLoading({
            title: '取消中...',
          });
          
          // 模拟取消订单请求
          setTimeout(() => {
            wx.hideLoading();
            wx.showToast({
              title: '订单已取消',
              icon: 'success'
            });
            
            // 更新订单状态
            this.setData({
              'orderInfo.status': 'completed',
              'orderInfo.statusText': '已取消'
            });
          }, 1500);
        }
      }
    });
  },
  
  contactService: function() {
    wx.makePhoneCall({
      phoneNumber: '400-123-4567',
    });
  },
  
  confirmPickup: function() {
    wx.showModal({
      title: '确认取餐',
      content: '请确认已收到您的餐品',
      success: (res) => {
        if (res.confirm) {
          wx.showLoading({
            title: '确认中...',
          });
          
          // 模拟确认取餐请求
          setTimeout(() => {
            wx.hideLoading();
            wx.showToast({
              title: '取餐成功',
              icon: 'success'
            });
            
            // 更新订单状态
            this.setData({
              'orderInfo.status': 'completed',
              'orderInfo.statusText': '已完成'
            });
          }, 1000);
        }
      }
    });
  }
});